DB Trigger - Sanitize App Backup Content
Trigger: trigger_sanitize_app_backup_content
Code:
CREATE TRIGGER trigger_sanitize_app_backup_content
BEFORE INSERT OR UPDATE OF backup_content
ON apps
FOR EACH ROW
EXECUTE FUNCTION sanitize_backup_content();
Environment:
- ✅ Production
- ✅ Staging
- ❌ Development
Description:
Similar to trigger_sanitize_app_content, this trigger is designed to sanitize the backup_content field of the apps table before inserting or updating records. It uses the sanitize_backup_content() function to replace any occurrences of the null character (represented as '\u0000') with an empty string while also removing any backslashes that precede the '\u0000' character. This ensures that not only null characters but also any escape sequences like '\u0000' are removed from the backup_content field. These escaped characters appear due to the backup_content field being serialized from a string to json and back to string by the ruby interpretor
Purpose:
- Prevents null characters from being stored in the
backup_contentfield. The null unicode characters impact the serialization to JSON, resulting in corresponding bugsnags.
Usage:
This trigger is automatically activated before any INSERT or UPDATE operation on the backup_content field of the apps table.
Removal: If this trigger needs to be removed for any reason, execute the following in the necessary environment:
DROP TRIGGER IF EXISTS trigger_sanitize_app_backup_content ON apps;
Related Documentation: